package cn.zz.veggie.web.controller.mgmt;

import java.util.List;

import cn.zz.veggie.web.types.dto.mgmt.user.MgmtUserSaveDto;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.zz.comm.types.IdNameObj;
import cn.zz.comm.core.types.query.PageQuery;
import cn.zz.comm.types.result.P;
import cn.zz.comm.web.annotation.BoxRespResult;
import cn.zz.veggie.application.service.UserAppService;
import cn.zz.veggie.web.types.vo.mgmt.MgmtUserBriefVo;
import cn.zz.veggie.web.types.vo.mgmt.user.MgmtUserVo;
import jakarta.validation.constraints.Positive;
import lombok.RequiredArgsConstructor;

/**
 * 用户接口
 * 
 * @author zhongq
 * @since 2024/4/25
 */
@Validated
@BoxRespResult
@RestController
@RequiredArgsConstructor
@RequestMapping("/mgmt/user")
public class MgmtUserController {
	private final UserAppService userAppService;

	/**
	 * 输入框搜索
	 */
	@GetMapping("/search")
	public List<IdNameObj<Integer>> inputSearch(String keyword) {
		return userAppService.adminInputSearch(keyword);
	}

	@GetMapping("/info")
	public MgmtUserBriefVo getUserInfo(@RequestParam Integer uid) {
		return userAppService.adminGetUserInfo(uid);
	}

	@GetMapping("/list")
	public P<MgmtUserVo> getUserList(String keyword, @RequestParam(defaultValue = "1") @Positive Integer current,
			@RequestParam(defaultValue = "10") @Positive Integer size) {
		return userAppService.adminGetList(keyword, PageQuery.of(current, size));
	}

	@PostMapping("/save")
	public void saveUser(@RequestBody @Validated MgmtUserSaveDto dto) {
		userAppService.adminSaveUser(dto);
	}
}